﻿Public MustInherit Class BasePrintUtil
    Implements IPrintUtil

    Private Shared anchoColumnas() As Integer
    Private Shared anchoTotal As Integer
    Private Shared anchoColumnasImp() As Integer
    Private Shared cabeceras As ListView.ColumnHeaderCollection
    Private Shared dtProd As DataTable


    Public Function CabeceraImpresion(e As System.Drawing.Printing.PrintPageEventArgs, prFont As System.Drawing.Font, yPos As Single) As Single Implements IPrintUtil.CabeceraImpresion
        Return Nothing
    End Function

    Protected Friend Shared Function ajustar(ByVal cadena As String, ByVal ancho As Integer, _
                                                   Optional ByRef alignRigth As Boolean = False) As String
        ' devuelve una cadena con el ancho indicado
        If cadena = Nothing OrElse cadena.Length = 0 Then
            Return New String(" "c, ancho)
        End If

        If alignRigth = True Then
            If ancho > cadena.Length Then cadena = New String(" "c, ancho - cadena.Length) & cadena
            Return cadena.Substring(cadena.Length - ancho, ancho)
        Else
            If ancho > cadena.Length Then cadena &= New String(" "c, ancho - cadena.Length)
            Return cadena.Substring(0, ancho)
        End If

        'If ancho > cadena.Length Then
        '    cadena &= New String(" "c, ancho - cadena.Length)
        'End If

        Return cadena.Substring(0, ancho)

    End Function

    Protected Overridable Sub CalcularAnchos(ByVal margins As Rectangle, ByVal prFont As Font)
        '------------------------------------------------------------
        ' ajustar el ancho de cada columna 
        ' según el ancho "requerido" y el "disponible"
        '------------------------------------------------------------
        ' el número de caracteres por cada línea
        Dim lineWidth As Single = margins.Width
        Dim tc As Integer = CInt(lineWidth / prFont.SizeInPoints + 0.5)
        ' el porcentaje a restar en cada columna
        Dim npc As Integer = ((anchoTotal - tc) * 100) \ anchoTotal
        If npc < 1 Then npc = 1
        ReDim anchoColumnasImp(anchoColumnas.Length - 1)
        For i As Integer = 0 To anchoColumnas.Length - 1
            Dim j As Integer = anchoColumnas(i) - CInt(anchoColumnas(i) * npc / 100) + 1
            If j > anchoColumnas(i) Then
                anchoColumnasImp(i) = anchoColumnas(i)
            Else
                anchoColumnasImp(i) = j
            End If
        Next
    End Sub

    Public Sub ToColumnHeaders(dt As System.Data.DataTable) Implements IPrintUtil.ToColumnHeaders

    End Sub

    Public Function LineaImpresión(ByRef lineaActual As Integer) As String Implements IPrintUtil.LineaImpresión

    End Function

    Public Function TituloImpresion(e As System.Drawing.Printing.PrintPageEventArgs, prFont As System.Drawing.Font, yPos As Single) As Single Implements IPrintUtil.TituloImpresion

    End Function
End Class
